package com.nightonke.boommenu.Piece;

import ohos.agp.components.ComponentContainer;
import ohos.app.Context;
import ohos.agp.components.Component;
import ohos.agp.components.StackLayout;
import ohos.agp.utils.Color;
import ohos.agp.utils.RectFloat;

/**
 * Created by Weiping Huang at 00:57 on 16/11/7
 * For Personal Open Source
 * Contact me at 2584541288@qq.com or nightonke@outlook.com
 */

public abstract class BoomPiece extends Component {

    private boolean requestLayoutNotFinish = false;

    public BoomPiece(Context context) {
        super(context);
    }

    public abstract void init(Color color, float cornerRadius);

    public abstract void setColor(Color color);

    public abstract void setColorRes(int colorRes);

    /**
     * place
     * @param rectF
     */
    public void place(RectFloat rectF) {
        ComponentContainer.LayoutConfig layoutParams = (ComponentContainer.LayoutConfig) getLayoutConfig();
        if (layoutParams != null) {
            layoutParams.setMarginLeft((int) rectF.left);
            layoutParams.setMarginTop((int) rectF.top);
            layoutParams.width = (int) rectF.right;
            layoutParams.height = (int) rectF.bottom;
            setLayoutConfig(layoutParams);
        }
    }

    /**
     * postLayout
     */
    @Override
    public void  postLayout() {
        if (requestLayoutNotFinish) return;
        requestLayoutNotFinish = true;
        super.postLayout();
        onLayout();
    }

    /**
     * onLayout
     */
    //@Override
    protected void onLayout() {
        requestLayoutNotFinish = false;
    }
}
